package com.bw.lyc.mvp.view.mine;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bw.lyc.R;
import com.bw.lyc.util.LogUtils;
import com.bw.lyc.util.StatusBarColorUtils;
import com.bw.lyc.util.ToastUtils;

public class UpdateNameActivity extends StatusBarColorUtils implements View.OnClickListener {

    private ImageView viewTopBack;
    private EditText updateNameEt;
    private Button updateNameBt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_name);
        initView();
        viewTopBack.setOnClickListener(this::onClick);
        updateNameBt.setOnClickListener(this::onClick);
        setStatusBarColor(Color.WHITE);
    }

    private void initView() {
        viewTopBack = (ImageView) findViewById(R.id.view_top_back);
        updateNameEt = (EditText) findViewById(R.id.update_name_et);
        updateNameBt = (Button) findViewById(R.id.update_name_bt);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.view_top_back) {
            finish();
        }
        if (id == R.id.update_name_bt) {
            String name = updateNameEt.getText().toString().trim();
            if (name.length() == 0) {
                ToastUtils.showMsg("用户名不能为空");
            } else {
                Intent intent = new Intent();
                intent.setAction("sends_user_name");
                intent.putExtra("send_user_name", name);
                sendBroadcast(intent);
                finish();
            }
        }
    }

    @Override
    public View addStatusView() {
        return f(R.id.update_name_relative);
    }
}